package com.yjd.comm.util;

/**
 * <b>description</b>：静态资源和图片工具类 <br>
 * <b>time</b>：2014-11-17下午1:43:38 <br>
 * <b>author</b>： ready likun_557@163.com
 */
public class StaticAndPicsUtil {

	public static String PICSDATA_DIR = "picsdata.dir";

	/**
	 * 根据打码图片的相对路径获取打码图片的完整路径
	 * 
	 * @param url
	 * @param isHTTPS
	 * @return
	 * @throws Exception
	 */
	public static String getPicsDataFullUrl(String url, boolean isHTTPS)
			throws Exception {
		return getPicsDataPrefUrl(isHTTPS) + url;
	}

	/**
	 * 获取认证打码图片的目录
	 * 
	 * @return
	 */
	public static String getPicsDataDir() {
		return FrameUtil.getWebResource(PICSDATA_DIR);
	}

	/**
	 * 获取打码图片的前缀
	 * 
	 * @param isHTTPS
	 * @return
	 */
	public static String getPicsDataPrefUrl(boolean isHTTPS) {
		return (isHTTPS ? FrameUtil
				.getWebResource(ServletUtil.UrlTypeEnum.PICS_HTTPS
						.getResourcesKey()) : FrameUtil
				.getWebResource(ServletUtil.UrlTypeEnum.PICS.getResourcesKey()))
				+ "/";
	}

	/**
	 * 根据打码图片的完整路径获取相对路径
	 * 
	 * @param fullUrl
	 * @return
	 * @throws Exception
	 */
	public static String getUserPicsRelativePathByFullUrl(String fullUrl)
			throws Exception {
		if (fullUrl.startsWith("https") || fullUrl.startsWith("HTTPS")) {
			return fullUrl.substring(getPicsDataPrefUrl(true).length());
		} else {
			return fullUrl.substring(getPicsDataPrefUrl(false).length());
		}
	}

}
